"""
@demo出品 仅供学习交流，请在下载后的24小时内完全删除 请勿将任何内容用于商业或非法目的，否则后果自负。
const $ = new Env("华住会");
export hweb=cookie
cron：52 8 * * *
"""
import os
import json
import requests
from datetime import datetime
from notify import send
def droplet_check_in(users_data):
    # 获取当前日期
    current_date = datetime.now()
    # 提取日期中的日
    day = current_date.day
    url = 'https://hweb-mbf.huazhu.com/api/signIn'

    datatime={
        'state':'1',
        'day':day
    }
    try:
        result = ""
        for user, token  in users_data.items():
            heard = {
                "Host": "hweb-mbf.huazhu.com",
                "Connection": "keep-alive",
                "Accept": "application/json, text/plain, */*",
                "Sec-Fetch-Site": "same-site",
                "Accept-Language": "zh-CN,zh-Hans;q=0.9",
                "Accept-Encoding": "gzip, deflate, br",
                "Sec-Fetch-Mode": "cors",
                "Content-Type": "application/x-www-form-urlencoded",
                "Origin": "https://campaign.huazhu.com",
                "User-Agent": "HUAZHU/ios/iPhone14,5/16.5/9.13.0/Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",
                "Client-Platform": "APP-IOS",
                "Referer": "https://campaign.huazhu.com/",
                "User-Token": "null",
                "Content-Length": "0",
                "Sec-Fetch-Dest": "empty",
                'Cookie': cookie
            }
            response = requests.post(url, headers=heard,data=datatime).json()
            qiandao=response["content"]["point"]
            sumdata = requests.post(url='https://hweb-mbf.huazhu.com/api/getPoint', headers=heard).json()["content"]["point"]
            print(sumdata)
            heara = {
                "Host": "newactivity.huazhu.com",
                "Connection": "keep-alive",
                "Accept": "application/json, text/plain, */*",
                "Sec-Fetch-Site": "same-site",
                "Accept-Language": "zh-CN,zh-Hans;q=0.9",
                "Accept-Encoding": "gzip, deflate, br",
                "Sec-Fetch-Mode": "cors",
                "Content-Type": "application/x-www-form-urlencoded",
                "Origin": "https://campaign.huazhu.com",
                "User-Agent": "HUAZHU/ios/iPhone14,5/16.5/9.13.0/Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148",
                "Referer": "https://campaign.huazhu.com/",
                "User-Token": token,
                "Content-Length": "289",
                "Sec-Fetch-Dest": "empty",
                'Cookie': cookie
            }
            param = {
                'activityId':'jfcj312',
                'appType':'web',
                'blackBox':'tdfpeyJ2IjoiWCtnWmJlWDErQzRsWjJGL05oTGJDWklmM2JsM09QRXgxSEF2MnAwS0lWbE4yMjNPcDNrOGs1Z3B0WDlDTlpybyIsIm9zIjozLCJ0IjoiNVdQVjE3MTY1MTg4MDk5ODhNSkYwenJnQTUifQ',
                'flag':'d4b17a0e-8e25-4f67-8a73-b9003b3d7d1d',
                'source':'CMS%E6%B4%BB%E5%8A%A8_jfcj312',
                'luckyDrawId':'278'

            }
            # zhuanpan = requests.post(url='https://newactivity.huazhu.com/campaign/template/luckyDraw', headers=heara,json=param).json()
            # # ["data"]["prize"]['prizeName']
            # print(zhuanpan)
            result += f"用户 {user} 签到获得 {qiandao} 积分,总共有 {sumdata} 积分。\n"
        return result
    except KeyError as error:
        print(f'token失效,{error}')
        return error

if __name__ == '__main__':
    users_data = os.getenv("huazhuhuiuser")

    users_data= eval(users_data)
    print(users_data)
    a=droplet_check_in(users_data)
    send("华住会签到", a)